//
//  XLProfileInputTableViewCell.m
//  Mine
//
//  Created by 于鹏 on 2017/8/30.
//  Copyright © 2017年 YIVIEW. All rights reserved.
//

#import "XLProfileInputTableViewCell.h"
#import "XLProfileInputCellModel.h"
//#import <XLBaseModule/XLCustomTextView.h>
//#import <Masonry.h>
#import "XLCustomTextView.h"
#import "Masonry.h"

@interface XLProfileInputTableViewCell ()<XLCustomTextViewDelegate>
@property (nonatomic, strong)XLCustomTextView *textView;
@end

@implementation XLProfileInputTableViewCell

+ (XLBaseTableViewCell *)cellWithIdentifier:(NSString *)cellIdentifier tableView:(UITableView *)tableView {
    XLProfileInputTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[XLProfileInputTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

- (void)setupUI {
    [super setupUI];
    [self.contentView addSubview:self.textView];
    self.textView.backgroundColor = [UIColor whiteColor];
    CGFloat spacing = 10;
    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(0, spacing, 0, spacing));
    }];
}

- (void)setupDataModel:(XLBaseCellModel *)model {
    [super setupDataModel:model];
    XLProfileInputCellModel *inputModel = (XLProfileInputCellModel *)model;
    self.textView.placeHolder = inputModel.placeholdText;
    self.textView.text = inputModel.text;
}

- (XLCustomTextView *)textView {
    if (!_textView) {
        _textView = [[XLCustomTextView alloc]init];
        _textView.borderColor = kXLWhiteColor;
        _textView.xl_customTextViewDelegate = self;
    }
    return _textView;
}

- (void)xl_customTextView:(XLCustomTextView *)textView updateText:(NSString *)text {
    XLProfileInputCellModel *model = (XLProfileInputCellModel *)self.cellModel;
    model.text = text;
    if (model.inputBlock) {
        model.inputBlock(text);
    }
}


@end
